package com.zyh.market.controller.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyh.market.model.R;
import com.zyh.market.model.dto.SystemProductInfoPageDto;
import com.zyh.market.service.ProductInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin/product/info")
@SaCheckLogin
@SaCheckRole(value = {"admin"})
public class ProductInfoAdminController {
    @Autowired
    private ProductInfoService productInfoService;

    /* 分页查询商品信息 */
    @GetMapping("/page")
    public R<Page> getProductInfoList(SystemProductInfoPageDto dto) {
        Page page = productInfoService.getProductInfoList(dto);
        return R.ok(page);
    }

    /* 查看商品更多信息 */
    @GetMapping("/detail/{id}")
    public R<Map> getDetail(@PathVariable("id") String id) {
        Map map = productInfoService.getDetail(id);
        return R.ok(map);
    }

    /* 通过商品审核 */
    @PutMapping("/pass/{id}")
    public R passProduct(@PathVariable("id") String id) {
        productInfoService.passProduct(id);
        return R.ok();
    }

    /* 不通过商品审核 */
    @PutMapping("/fail/{id}")
    public R failProduct(@PathVariable("id") String id) {
        productInfoService.failProduct(id);
        return R.ok();
    }

    /*  下架商品 */
    @PutMapping("/down/{id}")
    public R downProduct(@PathVariable("id") String id) {
        productInfoService.downProduct(id);
        return R.ok();
    }
}
